package com.tarena.lbs.activity.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class DeclareConfig {

    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue activityQ(){
        QueueBuilder queueBuilder = QueueBuilder.nonDurable("activity-queue");
        return queueBuilder.build();
    }

    /**
     * 声明交换机
     * @return
     */
    @Bean
    public Exchange activityEx(){
        ExchangeBuilder exBuilder = ExchangeBuilder.fanoutExchange("activity-ex");
        return exBuilder.build();
    }

    /**
     * 绑定队列和交换机
     * @return
     */
    @Bean
    public Binding bindActivityEQ(){
        BindingBuilder.GenericArgumentsConfigurer bindBuilder =
                BindingBuilder.bind(activityQ()).to(activityEx()).with("");
        return bindBuilder.noargs();
    }
}
